/*
 * Copyright (C) 2021 The Huawei International Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.zhpan.indicator.utils;

import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

/**
 * 日志打印
 *
 * @since 2021-04-21
 */
public class Log {

    private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x01, "MyDemo");
    private Log() {
    }

    /**
     * 格式化替换字符
     *
     * @param logMessageFormat message
     * @return String
     */
    public static String replaceFormat(String logMessageFormat) {
        return logMessageFormat.replaceAll("%([d|f|s])", "%{public}$1");
    }

    /**
     * debug 日志
     *
     * @param tag 标记
     * @param format 格式
     * @param args 打印参数
     */
    public static void d(String tag, String format, Object... args) {
        HiLog.debug(LABEL, tag + " " + replaceFormat(format), args);
    }

    /**
     * info 日志
     *
     * @param tag 标记
     * @param format 格式
     * @param args 打印参数
     */
    public static void i(String tag, String format, Object... args) {
        HiLog.info(LABEL, tag + " " + replaceFormat(format), args);
    }

    /**
     * 警告 日志
     *
     * @param tag 标记
     * @param format 格式
     * @param args 打印参数
     */
    public static void w(String tag, String format, Object... args) {
        HiLog.warn(LABEL, tag + " " + replaceFormat(format), args);
    }

    /**
     * error 日志
     *
     * @param tag 标记
     * @param format 格式
     * @param args 打印参数
     */
    public static void e(String tag, String format, Object... args) {
        HiLog.error(LABEL, tag + " " + replaceFormat(format), args);
    }
}
